package com.xhu.water_supply.web.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xhu.water_supply.dto.*;
import com.xhu.water_supply.service.SalaryService;
import com.xhu.water_supply.web.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/Salary")
public class SalaryController {
    @Autowired
    SalaryService salaryService;

    @PostMapping("/Refresh")
    public Result Refresh() {
        return ResultUtils.returnSuccess("更新工资成功");
    }

    @PostMapping("/getDefault")
    public Result<PageVO<SalaryDTO>> getDefault(SalarySearchDTO salarySearchDTO) {
        Page<SalaryDTO> page = PageHelper.startPage(salarySearchDTO.getPageNo(), salarySearchDTO.getPageSize());
        List<SalaryDTO> salaryList = salaryService.getDefault();
        PageVO<SalaryDTO> pageVO = new PageVO<>(salaryList, salarySearchDTO.getPageNo(), salarySearchDTO.getPageSize(), (int) page.getTotal());
        return ResultUtils.returnSuccess(ResultEnum.SUCCESS_QUERY_ADMIN_INFO.getMsg(), pageVO);
    }
    @PostMapping("/getSalary")
    public Result<PageVO<SalaryDTO>> getSalary(SalarySearchDTO salarySearchDTO) {
        Page<SalaryDTO> page = PageHelper.startPage(salarySearchDTO.getPageNo(), salarySearchDTO.getPageSize());
        List<SalaryDTO> salaryList = salaryService.getSalary(salarySearchDTO.getMonth(), salarySearchDTO.getId());
        PageVO<SalaryDTO> pageVO = new PageVO<>(salaryList, salarySearchDTO.getPageNo(), salarySearchDTO.getPageSize(), (int) page.getTotal());
        return ResultUtils.returnSuccess(ResultEnum.SUCCESS_QUERY_ADMIN_INFO.getMsg(), pageVO);
    }
}
